﻿$(document).ready(function () {
	$("#add-finance").dialog({
		autoOpen: false,
		height: 500,
		width: 600,
		modal: true
	});
	$("#substract-finance").dialog({
		autoOpen: false,
		height: 500,
		width: 600,
		modal: true
	});
	$("#StartTime").timepicker();
	$("#EndTime").timepicker();
	$("#StartDate").datepicker({
		showAnim: "fadeIn",
		dateFormat: 'dd MM yy',
		firstDay: 1,
		changeMonth: true,
		changeYear: true,
		gotoCurrent: true,
		onClose: function (selectedDate) {
			$("#EndDate").datepicker("option", "minDate", selectedDate);
		}
	});
	$("#EndDate").datepicker({
		showAnim: "fadeIn",
		dateFormat: 'dd MM yy',
		firstDay: 1,
		changeMonth: true,
		changeYear: true,
		gotoCurrent: true,
		onClose: function (selectedDate) {
			$("#StartDate").datepicker("option", "maxDate", selectedDate);
		}
	});
	$("#edit-setting").dialog({
		autoOpen: false,
		height: 500,
		width: 600,
		modal: true,
		buttons: [
			{
				text: "Update",
				click: function () {
					$("form#editSettingForm").submit();
				}
			},
			{
				text: "Cancel",
				click: function() {
					$(this).dialog("close");
				}
			}
		]
	});
	$("#cancel-withdraw").dialog({
		autoOpen: false,
		height: 200,
		width: 300,
		modal: true,
		buttons: [
			{
				text: "Cancel",
				click: function () {
					$("form#cancelWithdrawForm").submit();
				}
			},
			{
				text: "Close",
				click: function () {
					$(this).dialog("close");
				}
			}
		]
	});
});

function openAddFinanceWindow(userId, loginFilterValue) {
	$("#userIdAdd").val(userId);
	$("#loginFilterAdd").val(loginFilterValue);
	$('#add-finance').dialog('open');
}

function openSubstractFinanceWindow(userId, loginFilterValue) {
	$("#userIdSubstract").val(userId);
	$("#loginFilterSubstract").val(loginFilterValue);
	$('#substract-finance').dialog('open');
}

function openUpdateSettingWindow(id, key, value, description) {
	$("#Id").val(id);
	$("#settingKey").text(key);
	$("#Value").val(value);
	$("#Description").val(description);
	$('#edit-setting').dialog('open');
}

function openCancelWithdrawWindow(postingId, loginFilter) {
	$("#PostingId").val(postingId);
	$("#LoginFilter").text(loginFilter);
	$('#cancel-withdraw').dialog('open');
}